﻿#include "LMain.h"

namespace LibraryViewer
{

    int SemiNumericPathComparer::Compare(const std::string &s1, const std::string &s2)
    {
        std::string f1 = FileSystem::getFileName(s1);
        std::string f2 = FileSystem::getFileName(s2);

        if (IsNumeric(f1) && IsNumeric(f2))
        {
            if (std::stoi(f1) > std::stoi(f2))
            {
                return 1; //higher
            }
            if (std::stoi(f1) < std::stoi(f2))
            {
                return -1; //lower
            }
            if (std::stoi(f1) == std::stoi(f2))
            {
                return 0; //equal
            }
        }

        //numeric before string
        if (IsNumeric(f1) && !IsNumeric(f2))
        {
            return -1;
        }
        if (!IsNumeric(f1) && IsNumeric(f2))
        {
            return 1;
        }

//C# TO C++ CONVERTER TODO TASK: The following System.String compare method is not converted:
        return std::string::Compare(f1, f2, true);
    }

    bool SemiNumericPathComparer::IsNumeric(std::any value)
    {
        try
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
            int i = std::stoi(value.ToString());
            return true;
        }
        catch (const FormatException &e1)
        {
            return false;
        }
    }
}
